#!/bin/bash
function isGoodLog(){
	fileLog=$1
	if  [ ! -f ${fileLog} ]; then
	   return 1
	fi
	fileSize=`stat -c %s ${fileLog}`
	if [ $fileSize -lt 2048 ]; then
	   macAddress=`cat $fileLog|grep "develenv.macAddress"|cut -d'=' -f2`
	   #Las instalaciones tienen que estar separadas como mínimo un minuto, sino se considera spam
	   if [ "$macAddress" != "" ]; then 
	      cp ${fileLog} $LOGSDIR/`date +%Y-%m-%d_%H:%M`-${macAddress}.log 
	      rm -Rf $fileLog
	      return 0
	   fi
	fi
	rm -Rf $fileLog
	return 1
}


WORKDIR="../../../data/stats/develenv"
LOGSDIR=$WORKDIR/logs
COUNTERSDIR=$WORKDIR/counters
mkdir -p $WORKDIR
mkdir -p $LOGSDIR
mkdir -p $COUNTERSDIR

if [ "$#" != 1 ]; then
   exit 1
fi
isGoodLog $1
if [ "$?" == 0 ]; then
   ../private/stats/counter.sh "installations"
fi

